<?php
function not_null($a){
	if(is_null($a)){
		return false;
	}
	else{
		return true;
	}
}
function tuga_multiquery($sql) {
	CONN('MYI');
	$GLOBALS['MYI']->multi_query($sql);
	$result_array = array();
	while ($GLOBALS['MYI']->more_results()) {
		$GLOBALS['MYI']->next_result();
		$return_result = array();
		if ($result = $GLOBALS['MYI']->store_result()) {
			while ($row = $result->fetch_row()) {
				$return_result[] = $row;
			}
			$result_array[] = $return_result;
			$result->free();
		}
	}
	$GLOBALS['MYI']->close();
	if (isset($result_array[0])) {
		return $result_array[0];
	} else {
		return null;
	}
}

/*
 * Atenção, mostra os valores alterado
 * Caso haja uma virgula na posicao, está virgula é removida
 */

function implode_with_key($a) {
	$result = '';
	while ($posicao = current($a)) {
		$posicao = str_replace(',', '', $posicao);
		$result = $result . key($a) . '=>' . $posicao . ',';
		next($a);
	}

	$result = substr($result, 0, -1);
	return $result;
}

function erro($a) {
	if (is_array($a)) {
		$a = implode_with_key($a);
	}
	error_log($a, 0);
}

function getLastWord($sentence) {
	$mirror_array = explode(' ', $sentence);
	$mirror_num = count($mirror_array);
	$lastword = $mirror_array[$mirror_num - 1];
	return $lastword;
}

function correspondenteRusslav($idCorrespondente) {
	if ($idCorrespondente == 306) {
		return true;
	} else {
		return false;
	}
}

function printArray($result) {
	echo '<pre>';
	print_r($result);
	echo '</pre>';
}

function reverte($s) {
	$s = str_replace('&amp;', '&', $s);
	$s = str_replace("&apos;", "'", $s);
	$s = str_replace('&quot;', '"', $s);
	$s = str_replace('&lt;', '<', $s);
	$s = str_replace('&gt;', '>', $s);
	return $s;
}
function bpcorrconv($bnk, $corr, $acc, $acctype, $acc_pre, $acc_suf, $acc_mod) {
    if ($acc_suf != '') {
        $acc_suf = '-' . $acc_suf;
    }
    if (($corr == 301 || $corr == 300) && $bnk == 53) {
        if ($acc_mod != '' && $acctype == 2) {
            $result_acc = $acc . '-' . $acc_mod;
        } else {
            $result_acc = $acc . $acc_suf;
        }
        if ($acctype == 2) {
            $result_acc = $acc_pre . $result_acc;
        }
    } elseif ($corr == 305 && $bnk == 143) {
        if ($acc_pre != '') {
            $acc_pre = $acc_pre . '/';
        }
        $result_acc = $acc_pre . $acc . $acc_suf;
    } else {
        $result_acc = $acc . $acc_suf;
    }
    return $result_acc;
}